package com.quasar.hpatient.view.adapter.render;

import android.content.Context;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ada.adapter.RenderAdapter;
import com.ada.adapter.RenderBuiler;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.PrescriptionDayData;
import com.quasar.hpatient.utils.Spanny;
import com.quasar.hpatient.widget.MyListView;

/**
 * 现在药单外层列表
 * Created by Administrator on 2017/5/24 0024.
 */

public class NowDrugRender extends RenderBuiler<PrescriptionDayData.ListBean> implements View.OnClickListener {


    LinearLayout ll_layout;
    TextView prescription_tv_time;//指导时间
    TextView prescription_tv_name;//指导医师
    MyListView mlv_list;
    TextView tv_hospital;

    private String stats;

    public String getStats() {
        return stats;
    }

    public void setStats(String stats) {
        this.stats = stats;
    }

    public NowDrugRender(Context context) {
        super(context);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_layout:
                break;
        }

    }

    RenderAdapter<PrescriptionDayData.ListBean> adapter;

    @Override
    public void render() {

        if (getContent().getrName() != null && getContent().getrName().length() > 0) {
            prescription_tv_name.setText(getContent().getrName());
        } else {
            prescription_tv_name.setText("自己添加");
        }

        //药单创建时间
        if (getContent().getCreateTime() != null) {
            prescription_tv_time.setText(getContent().getCreateTime().substring(0, 10));
        }

        //医院
        Spanny spanny = new Spanny();
        if (getContent().getperscripDate() != null) {
            if (getContent().getperscripDate().getName() != null) {
                spanny.append(getContent().getperscripDate().getName(), new ForegroundColorSpan(color(R.color.btcolor)));
            }
        }
        tv_hospital.setText(spanny);

        //药品规格
        DrugsTypeRender drugsTypeRender = new DrugsTypeRender(getContext());
        drugsTypeRender.setStats(getStats());
        adapter = new RenderAdapter<>(getContext(), drugsTypeRender);

        adapter.add(getContent());

        mlv_list.setAdapter(adapter);

    }

    @Override
    protected void setUpView(View view) {

        ll_layout = (LinearLayout) view.findViewById(R.id.ll_layout);
        prescription_tv_time = (TextView) view.findViewById(R.id.prescription_tv_time);
        prescription_tv_name = (TextView) view.findViewById(R.id.prescription_tv_name);
        mlv_list = (MyListView) view.findViewById(R.id.mlv_list);
        mlv_list.setVisibility(View.VISIBLE);
        tv_hospital = (TextView) view.findViewById(R.id.tv_hospital);
    }

    @Override
    protected void hookListeners(View view) {
        ll_layout.setOnClickListener(this);
    }

    @Override
    protected int getlayoutid() {
        return R.layout.history_drug_item;
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
